/**
 * 
 */
package javapop.framework.generic.tool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import javapop.framework.ParseInput;
import javapop.framework.generic.GChoice;
import javapop.framework.generic.GDefRegle;
import javapop.framework.generic.GExprBracket;
import javapop.framework.generic.GExprOperand;
import javapop.framework.generic.GExprOperator;
import javapop.framework.generic.GExprParser;
import javapop.framework.generic.GIgnore;
import javapop.framework.generic.GKeyword;
import javapop.framework.generic.GKeywords;
import javapop.framework.generic.GListOf;
import javapop.framework.generic.GLiteral;
import javapop.framework.generic.GMaybe;
import javapop.framework.generic.GMaybeOrDefault;
import javapop.framework.generic.GMeta;
import javapop.framework.generic.GParser;
import javapop.framework.generic.GRefParser;
import javapop.framework.generic.GRegexp;
import javapop.framework.generic.GRegexpWithoutKeywords;
import javapop.framework.generic.GRegle;
import javapop.framework.generic.GTransform;
import javapop.framework.generic.GTuple;
import javapop.framework.generic.GrammarTree;
import javapop.utils.Triple;

/**
 * @author hakim
 *
 */
public class BuildSampleGrammar {
	private HashMap<String, Triple<ArrayList<GExprBracket>, ArrayList<GExprOperand>, ArrayList<GExprOperator>>> exprs;
	private HashMap<String, BuildSampleNode> map;
	private BuildSampleNode start;
	private ArrayList<BuildSampleNode> open;

	public BuildSampleGrammar() {
		exprs = new HashMap<String, Triple<ArrayList<GExprBracket>,ArrayList<GExprOperand>,ArrayList<GExprOperator>>>();
		map = new HashMap<String, BuildSampleNode>();
	}
	
	class BuildSampleNode implements Iterable<BuildSampleNode>{
		GParser parser;
		ArrayList<BuildSampleNode> children;
		
		
		BuildSampleNode(GParser parser) {
			children = new ArrayList<BuildSampleGrammar.BuildSampleNode>();
			this.parser = parser;
		}
		
		void add(BuildSampleNode node) {
			children.add(node);
		}

		@Override
		public Iterator<BuildSampleNode> iterator() {
			return children.iterator();
		}
	}
	
	class RefSampleNode extends BuildSampleNode {

		RefSampleNode(GParser parser) {
			super(parser);
		}
		
		
	}
	
	
	
	// ---------------------------------------------------------------------------------
	class GrammarGraphConstructor implements GrammarVisitor<BuildSampleNode, String, GrammarVisitorException> {

		@Override
		public void init(List<GrammarTree> grammar)
				throws GrammarVisitorException {
			// TODO Auto-generated method stub
			
		}

		@Override
		public String treatment(ParseInput input)
				throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GChoice o) throws GrammarVisitorException {
			BuildSampleNode n = new BuildSampleNode(o);
			for (GParser p : o.getChoices()) {
				n.add(p.visit(this));
			}
			return n;
		}

		@Override
		public BuildSampleNode visit(GDefRegle r)
				throws GrammarVisitorException {
			return null;
		}

		@Override
		public BuildSampleNode visit(GExprBracket b)
				throws GrammarVisitorException {
			Triple<ArrayList<GExprBracket>, ArrayList<GExprOperand>, ArrayList<GExprOperator>> t = exprs.get(b.getParser());
			t.getFirst().add(b);
			return null;
		}

		@Override
		public BuildSampleNode visit(GExprOperand o)
				throws GrammarVisitorException {
			Triple<ArrayList<GExprBracket>, ArrayList<GExprOperand>, ArrayList<GExprOperator>> t = exprs.get(o.getParser());
			t.getSecond().add(o);
			return null;
		}

		@Override
		public BuildSampleNode visit(GExprOperator o)
				throws GrammarVisitorException {
			Triple<ArrayList<GExprBracket>, ArrayList<GExprOperand>, ArrayList<GExprOperator>> t = exprs.get(o.getParser());
			t.getThird().add(o);
			return null;
		}

		@Override
		public BuildSampleNode visit(GExprParser o)
				throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GIgnore o) throws GrammarVisitorException {
			return null;
		}

		@Override
		public BuildSampleNode visit(GKeyword o) throws GrammarVisitorException {
			return null;
		}

		@Override
		public BuildSampleNode visit(GListOf o) throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GLiteral o) throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GMaybeOrDefault o)
				throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GMeta o) throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GRefParser o)
				throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GRegexp o) throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GRegexpWithoutKeywords o)
				throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GRegle o) throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GTransform o)
				throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GTuple o) throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GKeywords o)
				throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public BuildSampleNode visit(GMaybe gMaybe)
				throws GrammarVisitorException {
			// TODO Auto-generated method stub
			return null;
		}
		
	}
}
